package com.ethan.simple;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * @Description:
 * @Author ethan
 * @CreateDate: 2022/05/29 上午7:51
 * @UpdateDate: 2022/05/29 上午7:51
 * @Version 1.0
 */
public class Test {
    public static void main(String[] args) throws IOException {

        ObjectMapper objectMapper = new ObjectMapper();
        //序列化
        String userStr = "{\"id\":1,\"name\":\"ethan\",\"tel\":\"12341313\"}";
        User readUser =  objectMapper.readValue(userStr,User.class);
        System.out.println("tel:"+readUser.getTel());

        //反序列化
        User user = new User(1L,"ethan","12341313");
        String result =  objectMapper.writeValueAsString(user);
        System.out.println(result);
    }
}
